﻿rem @echo off
setlocal enabledelayedexpansion
set INFO_PATH=info.ini
set LOG_PATH=Revision.txt
set SIMPLE_INFO=simpleInfo.txt
set GIT_PATH="C:\Program Files\Git\cmd\git.exe"
cd %~dp0
set revision_Path=%cd%
cd..
cd..
set source_Path=%cd%
cd..
set trunk_Path=%cd%
cd source/PlatformApp/GmQtGuiImplementation

rem 判断绝对路径下的svn.exe
rem -------------------------------------------
if exist !GIT_PATH! (
     goto :GitOperator 
 )
rem 获取环境变量下svn.exe的路径
rem -------------------------------------------
set LIST_PATH=sysPath.txt  
set RES_PATH=svnPath.txt

set new="%path:;=" "%"
for %%i in (%new%) do (
 echo %%i >> !LIST_PATH!
)

findstr /ic:"Git\cmd"  !LIST_PATH! >> !RES_PATH!
rem set GITPATH="\git.exe"
for /f "delims=" %%i in (!RES_PATH!) do (
    set str=%%i
    goto :end
)
:end

set str=%str:"=%
rem 去掉字符串中的空格

:delright
if "!str:~-1!"==" " (
    set "str=!str:~0,-1!"
    goto delright
)
set SYS_PATH=!str!\git.exe
del /f  !LIST_PATH!
del /f  !RES_PATH!

rem 判断环境变量下的svn.exe
rem ------------------------------------------
if exist !SYS_PATH! ( 
    goto :GitOperator 
)
goto :VersionEof

rem 调用SVN获取代码当前的版本号
rem ------------------------------------------
:GitOperator
	cd %trunk_Path%
	git log -1 --pretty=format:"%%h %%cd" --date=iso > !revision_Path!\!INFO_PATH!
	cd %revision_Path%
    findstr /c:"Last Changed Rev"  !INFO_PATH! > !SIMPLE_INFO!
    for /f "tokens=1" %%i in (!INFO_PATH!) do (
        echo  %%i > !LOG_PATH!
        goto :GitTime    
    )

:GitTime
	findstr /c:"Last Changed Date:"  !INFO_PATH! > !SIMPLE_INFO!
    for /f "tokens=2,3" %%i in (!INFO_PATH!) do (
        echo  %%i %%j>> !LOG_PATH!
        goto :TxtCopy    
    )
 
:TxtCopy    
    set OUTDIR=%~1
    set CONFIG=%~2
    set PLATFORM=%~3
    xcopy /y /f !LOG_PATH!  !OUTDIR!
    del /f  !SIMPLE_INFO!

:VersionEof
